package ui.units {

	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import globals.Global;
	
	import mx.core.MovieClipAsset;
	
	import util.DisplayUtil;
	
	public class UnitView extends Sprite {
		
		public var url:String;
		public var current:int;
		public var total:uint;
		public var lifeTime:uint;
		private var list:Array;
		public var view:Bitmap;
		private var unit:BaseUnit;
		public var mc:MovieClip;

		public function UnitView(baseUnit:BaseUnit) {
			super();
			
			unit = baseUnit;
			list = new Array();
			current = -1;
		}
		
		public function init(url:String, domain:String):void {
			this.url = url;
			current = 0;
			mc = Global.assetsManager.getAssetsAsMovieClip(url, domain);
			addChild(mc);
		}
		
		public function gotoAndPlay(frameName:String):void {
			mc.gotoAndPlay(frameName);
		}
		
		public function gotoAndStop(frameName:String):void {
			mc.gotoAndStop(frameName);
		}
		
		public function update(action:uint, diretion:uint):void {
			current++;
			if (current >= total) {
				current = 0;
				if (!unit.repeat) {
					Global.unitManager.removeMagic(unit.id);
				}
			}
//			Global.assetsManager.updateUnit(url, current, action, diretion, this);
		}
		
		public function clear():void {
			list = new Array();
			current = -1;
		}
	}
}